<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>盒模型</title>
    <style>
        #div1,
        #div2 {
            width: 100px;
            padding: 10px;
            border: 1px solid #ccc;
            margin: 10px;
        }

        #div1 {
            box-sizing: border-box;
        }
    </style>
</head>

<body>
    <div id="div1">
        this is div1
    </div>
    <div id="div2">
        this is div2
    </div>
    <script>
        console.log(document.getElementById('div1').offsetWidth);
        console.log(document.getElementById('div2').offsetWidth);
    </script>
</body>

</html>